import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/doctor',
    component: Layout,
    redirect: '/doctor/department',
    name: 'doctor',
    meta: { title: '医生管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/department/index'),
        meta: { title: '科室管理', icon: 'el-icon-loading' }
      },
      {
        path: 'con',
        name: 'con',
        component: () => import('@/views/banner/index'),
        meta: { title: '角色管理', icon: 'el-icon-user' }
      },
      {
        path: 'con',
        name: 'con',
        component: () => import('@/views/banner/index'),
        meta: { title: '员工管理', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/mediacal',
    component: Layout,
    redirect: '/mediacal/drug',
    name: 'mediacal',
    meta: { title: '药品信息维护', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/banner/index'),
        meta: { title: '药品管理', icon: 'el-icon-grape' }
      },
      {
        path: 'taste',
        name: 'taste',
        component: () => import('@/views/banner/index'),
        meta: { title: '供应商管理', icon: 'el-icon-ice-cream-round' }
      }
    ]
  },
  {
    path: '/hz',
    component: Layout,
    redirect: '/hz/drug',
    name: 'mediacal',
    meta: { title: '患者管理', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/banner/index'),
        meta: { title: '患者管理', icon: 'el-icon-user' }
      },
      {
        path: 'category2',
        name: 'category2',
        component: () => import('@/views/banner/index'),
        meta: { title: '就诊记录', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/hz2',
    component: Layout,
    redirect: '/hz2/drug',
    name: 'mediacal',
    meta: { title: '系统管理', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/banner/index'),
        meta: { title: '系统管理', icon: 'el-icon-user' }
      }
    ]
  },
  
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
